#include <stdio.h>
#include <vector>
#include <unistd.h>

std::vector<char*>* pool = NULL;

extern "C"
{
     __attribute__((constructor)) void init() {
        pool = new std::vector<char*>;
        for (size_t i = 0; i < 2; i++)
        {
            pool->push_back(new char[1024]);
            printf("%p\t", pool->back());
        }
            printf("\n");
        int ret = fork();
        if(ret == 0) {
            printf("child. %d\n", getpid());
        } else {
            printf("parent. %d\n", getpid());
        }
    }  

    void printMessage(const char* msg) {
            printf("pid. %d\n", getpid());
        for (size_t i = 0; i < 10; i++)
        {
            pool->push_back(new char[1024]);
            printf("%p\t", pool->back());
        }
            printf("\n");
    }

    __attribute__((destructor)) void cleanup() {
        // printf("%s, %d\n", __FILE__, __LINE__);
        // for (auto it : *pool)
        // {
        //     printf("%x\t", it);
        //     delete[] it;
        // }
        // printf("%s, %d\n", __FILE__, pool->size());
        // delete pool;
    }  
}
